package org.graduation.model.common.project;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;

@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName(value = "task")
public class Task {
    @JsonSerialize(using = ToStringSerializer.class)
    private Long pId;
    @JsonSerialize(using = ToStringSerializer.class)
    private Long phaseId;
    @TableId(value = "task_id", type = IdType.ASSIGN_ID)
    @JsonSerialize(using = ToStringSerializer.class)
    private Long taskId;
    private String name;
    private String description;
    @TableField("begin_time")
    private Date beginTime;
    @TableField("end_time")
    private Date endTime;
    private Integer status;

    private Date created;

    private Integer createUser;

    public void initStatus() {
        Long currentTime = System.currentTimeMillis();
        if (getBeginTime().getTime() > currentTime) {
            setStatus(TaskStatus.READY.getValue());
        } else if (getEndTime().getTime() > currentTime) {
            setStatus(TaskStatus.DOING.getValue());
        } else {
            setStatus(TaskStatus.END.getValue());
        }
    }
}
